package com.woniuxy.provider;

import com.work.framework.pojo.Enshrine;
import javafx.beans.binding.When;
import jdk.nashorn.internal.objects.annotations.Where;
import org.apache.ibatis.jdbc.SQL;

/**
 * @author fengyao
 * @version 1.0
 * @date 2019/9/19 0019 下午 2:40
 */

public class GoodsSqlProvider {
    /**
     * 类型查询
     * select * from goods g INNER JOIN auction a on g.gid=a.gid and a.valid=1 INNER JOIN picture p on p.gid=g.gid;
     * @param cid
     * @param count
     * @param sort
     * @return
     */
    public String hotGoodsByClassify(int cid, int count, boolean sort) {
        System.out.println("进入方法");
        return new SQL() {
            {
                SELECT("*");
                FROM("goods g INNER JOIN auction a on g.gid=a.gid and a.valid=1 INNER JOIN picture p on p.gid=g.gid and p.status=0 ");
                if (cid != 0) {
                    WHERE( " g.cid=#{cid}");
                }
                if (sort) {
                    ORDER_BY(" enshrine desc limit 0,#{count}");
                } else {
                    ORDER_BY(" enshrine limit 0,#{count}");
                }
            }
        }.toString();
    }

    /**
     * 状态查询
     * select *
     * from goods g INNER JOIN auction a on g.gid=a.gid and a.valid=1 INNER JOIN picture p on p.gid=g.gid
     * where a.status=#{status}
     * order by enshrine desc limit 0,#{sort}
     * @param status 商品状态
     * @param count 返回结果数量
     * @param sort 排序
     * @return SQL语句
     */
    public String hotGoodsByStatus(int status, int count, boolean sort) {
        System.out.println("进入方法");
        return new SQL() {
            {
                SELECT("*");
                FROM("goods g INNER JOIN auction a on g.gid=a.gid and a.valid=1 INNER JOIN picture p on p.gid=g.gid and p.status=0 ");
                if (status != 0) {
                    WHERE(" a.status=#{status}");
                }
                if (sort) {
                    ORDER_BY(" enshrine desc limit 0,#{count}");
                } else {
                    ORDER_BY(" enshrine limit 0,#{count}");
                }
            }
        }.toString();
    }

    /**
     * 查询shop商品种类
     * select *
     * from goods g INNER JOIN auction a on g.gid=a.gid and a.valid=1 INNER JOIN picture p on p.gid=g.gid
     * where a.status=#{status} and g.gname like concat('%',#{name},'%') and g.countyid=#{countyid}
     * order by #{sortType} desc
     * @param cid 商品种类
     * @param sortType 按照什么排序
     * @param sort 正序倒叙
     * @return
     */
    public String showGoodsList(Integer countyid,Integer cid,String sortType, Integer sort,String name) {
        System.out.println("进入方法");
        return new SQL() {
            {
                SELECT("*");
                FROM("goods g INNER JOIN auction a on g.gid=a.gid and a.valid=1 INNER JOIN picture p on p.gid=g.gid and p.status=0 ");
                if (cid != 0) {
                    WHERE(" g.cid=#{cid}");
                }
//                if(name!="" && name!=null &&name!="null"){
                if(!name.equals("fuck")){
                    WHERE(" g.gname like concat('%',#{name},'%')");
                }
                if (countyid != 0) {
                    WHERE(" g.countyid=#{countyid}");
                }
                if (sort==1) {
                    ORDER_BY(" #{sortType} ");
                } else {
                    ORDER_BY(" #{sortType} desc");
                }
            }
        }.toString();
    }
}
